#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
using namespace std;

bool IsPrime(long long& num)
{
	if (num < 2)
		return false;
	for (int i = 2; i < sqrt(num); i++)
		if (num % i == 0)	return false;
	return true;
}

int main()
{
	long long n;
	cin >> n;
	while (n--)
	{
		long long a, b;
		cin >> a >> b;
		if (a == 1 && IsPrime(b) || b == 1 && IsPrime(a))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}

	return 0;
}